feat: Add linkClaimAttemptToExternalUser to Agents module#1652
Conversation
Add POST /agents/claims/attempts endpoint support to the Node SDK. This allows admin API consumers to attach a user to a claim attempt and retrieve the code needed for the agent to complete the claim. Closes AUTH-6647 Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Original prompt from madison.packer
|
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Greptile SummaryThis PR adds
Confidence Score: 4/5The change is isolated to new code with no existing callers affected, but the HTTP verb used (PATCH) contradicts the PR description (POST), which needs confirmation against the actual API before shipping. The implementation and tests consistently use PATCH, while the PR description documents the endpoint as POST. If the WorkOS backend only accepts POST at /agents/claims/attempts, every SDK call to this method will fail with a 405 response. The rest of the change — serialization, deserialization, types, and test coverage — is well-structured and follows the codebase patterns. src/agents/agents.ts — the HTTP verb (PATCH vs POST) should be verified against the API spec before merging. Important Files Changed
|
…d type discriminator Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
| * @throws {ConflictException} 409 - Organization selection required, external ID conflict, or already claimed. | ||
| * @throws {GoneException} 410 - Claim or user code expired. | ||
| */ | ||
| async linkClaimAttemptToExternalUser( |
There was a problem hiding this comment.
I don't have a strong opinion here on the name, but just flagging that this is different from the other SDKs' generated method (createAttempt) so I'm wondering if we should rename this to something more similar or the same.
There was a problem hiding this comment.
This name was a deliberate choice by @m0tzy earlier in the design of this endpoint. The autogenerated SDKs surface a generic createAttempt(type=...) because they're driven directly off the OpenAPI operation, but for the hand-written Node method Madison wanted the name to describe what the operation actually does — link an external user to a claim attempt — rather than expose the lower-level type discriminator. The corresponding docs/API summary was also updated to "Link a claim attempt to an external user" to match.
Happy to rename to align with the generated SDKs (createAttempt) if the team would rather keep them consistent — deferring to @m0tzy on the final call since it was a product decision.
There was a problem hiding this comment.
Update on this: we resolved the divergence by switching the endpoint from POST to PATCH /agents/claims/attempts (it modifies an existing claim attempt rather than creating one — the agent already created it). The generated SDKs now surface a generic updateAttempts({ type: 'link_external_user', ... }), where the type arg disambiguates the operation. This hand-written Node SDK keeps the ergonomic linkClaimAttemptToExternalUser(...) wrapper over the same PATCH call (it hardcodes type internally). So the remaining name difference is intentional — hand-written SDKs are allowed to be friendlier than the generated ones. Server + docs are updated in workos/workos#64535.
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
| const { data } = await this.workos.patch<SerializedClaimAttemptResponse>( | ||
| '/agents/claims/attempts', | ||
| serializeLinkClaimAttemptToExternalUserOptions(options), | ||
| ); |
There was a problem hiding this comment.
HTTP method contradicts the PR description
The PR description explicitly states this wraps POST /agents/claims/attempts, but the implementation calls this.workos.patch(...). If the WorkOS API endpoint only accepts POST, every call to linkClaimAttemptToExternalUser will fail with a 405 Method Not Allowed response. The tests assert 'PATCH' which keeps them consistent with the implementation, but they won't catch this kind of server-side rejection. Please confirm the intended HTTP verb against the API spec and align the implementation, tests, and PR description accordingly.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/agents.ts
Line: 67-70
Comment:
**HTTP method contradicts the PR description**
The PR description explicitly states this wraps `POST /agents/claims/attempts`, but the implementation calls `this.workos.patch(...)`. If the WorkOS API endpoint only accepts `POST`, every call to `linkClaimAttemptToExternalUser` will fail with a `405 Method Not Allowed` response. The tests assert `'PATCH'` which keeps them consistent with the implementation, but they won't catch this kind of server-side rejection. Please confirm the intended HTTP verb against the API spec and align the implementation, tests, and PR description accordingly.
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
PATCH is the intended verb — the endpoint was switched from POST to PATCH in the companion API PR (workos/workos#64535) since it modifies an already-existing claim attempt. I verified the server accepts PATCH via the API e2e suite (agent-admin.controller.e2e-spec.ts, all cases green). The stale "POST" in the description was the only mismatch — I've updated the PR description to say PATCH. No 405 risk.
Description
Adds
workos.agents.linkClaimAttemptToExternalUser(options)wrappingPATCH /agents/claims/attempts.The serializer hardcodes
type: 'link_external_user'so callers don't need to pass it:Types:
LinkClaimAttemptToExternalUserOptions,ClaimAttemptResponse,ClaimAttemptOrganizationThe endpoint uses
PATCHbecause it modifies an existing claim attempt (the agent already created it) rather than creating one. Generated SDKs surface a genericupdateAttempts({ type: 'link_external_user', ... }); this hand-written SDK keeps the ergonomiclinkClaimAttemptToExternalUserwrapper.Documentation
API reference docs updated in the companion monorepo PR (workos/workos#64535).
Closes AUTH-6647
Link to Devin session: https://app.devin.ai/sessions/4c6130f5dc744691a1c9fe409b253aac
Requested by: @m0tzy